package com.py.credit.clean.code;

import java.lang.reflect.Method;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

/**
 * 依据行政相对人类别（CF_XZXDRLB或者XK_XZXDRLB）进行判断，行政相对人类别为法人及非法人组织时，按照统一社会信用代码规则校验，行政相对人类别为个体工商户，按照统一社会信用代码规则校验或者输入17个0+X(不分大小写）也通过。
验证不通过的提示：不是正确的统一社会信用代码
 * @author zhangzf
 *
 */
public class XydmCheckByXdrlb {
	 public final static String XYDM_RULE_PACKAGE = "com.py.credit.clean.code.XydmCheck";
	public boolean run(Map<String, Object> map, String extend) {
		if(String.valueOf(map.get("tableId")).equals("210001")) {
			if("个体工商户".equals(String.valueOf(map.get("CF_XZXDRLB")))) {
				if("00000000000000000X".equals(String.valueOf(map.get("A000002")))||"00000000000000000x".equals(String.valueOf(map.get("A000002")))) {
					return true;
				}else {
					try {
		                Class<?> c = Class.forName(XYDM_RULE_PACKAGE);
		                Method m = c.getMethod("run", String.class, String.class);
		                String data = (String) map.get("A000002");
		                return (boolean) m.invoke(c.newInstance(), data, "");
		            } catch (Exception e) {
		                return false;
		            }
				}
			}else if("法人及非法人组织".equals(String.valueOf(map.get("CF_XZXDRLB")))){
				try {
					Class<?> c = Class.forName(XYDM_RULE_PACKAGE);
					Method m = c.getMethod("run", String.class, String.class);
					String data = (String) map.get("A000002");
					return (boolean) m.invoke(c.newInstance(), data, "");
				} catch (Exception e) {
					return false;
				}
			}else if("自然人".equals(String.valueOf(map.get("CF_XZXDRLB")))){
				try {
//					Class<?> c = Class.forName(XYDM_RULE_PACKAGE);
//					Method m = c.getMethod("run", String.class, String.class);
//					String data = (String) map.get("A000002");
					return true;
				} catch (Exception e) {
					return false;
				}
			}else {
	        	return false;
	        }
			
		}else if(String.valueOf(map.get("tableId")).equals("210000")){
			if("个体工商户".equals(String.valueOf(map.get("XK_XZXDRLB")))) {
			if("00000000000000000X".equals(String.valueOf(map.get("A000002")))||"00000000000000000x".equals(String.valueOf(map.get("A000002")))) {
					return true;
				}else {
					try {
		                Class<?> c = Class.forName(XYDM_RULE_PACKAGE);
		                Method m = c.getMethod("run", String.class, String.class);
		                String data = (String) map.get("A000002");
		                return (boolean) m.invoke(c.newInstance(), data, "");
		            } catch (Exception e) {
		                return false;
		            }
				}
			}else if("法人及非法人组织".equals(String.valueOf(map.get("XK_XZXDRLB")))){
				try {
	                Class<?> c = Class.forName(XYDM_RULE_PACKAGE);
	                Method m = c.getMethod("run", String.class, String.class);
	                String data = (String) map.get("A000002");
	                return (boolean) m.invoke(c.newInstance(), data, "");
	            } catch (Exception e) {
	                return false;
	            }
			}else if("自然人".equals(String.valueOf(map.get("XK_XZXDRLB")))){
				try {
//					Class<?> c = Class.forName(XYDM_RULE_PACKAGE);
//					Method m = c.getMethod("run", String.class, String.class);
//					String data = (String) map.get("A000002");
					return true;
				} catch (Exception e) {
					return false;
				}
			}else {
	        	return false;
	        }
			}
		return true;
		
	

	}
}	
